<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

function themeConfig($form) {
    $logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点LOGO地址'), _t('在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO'));
    $form->addInput($logoUrl);

    $filing = new Typecho_Widget_Helper_Form_Element_Text('filing', NULL, NULL, _t('ICP备案号'), _t('底部显示：ICP备案号'));
    $form->addInput($filing);

    $copyright = new Typecho_Widget_Helper_Form_Element_Text('copyright', NULL, NULL, _t('版权信息'), _t('底部显示：版权信息'));
    $form->addInput($copyright);

    $keywords = new Typecho_Widget_Helper_Form_Element_Textarea('keywords', NULL, NULL, _t('SEO:KeyWords'), _t('SEO关键词优化'));
    $form->addInput($keywords->addRule('maxLength', _t('最多不要超过100个字符'),100));

    $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('SEO:Description'), _t('SEO描述优化'));
    $form->addInput($description->addRule('maxLength', _t('最多不要超过200个字符'),200));


    $sidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('sidebarBlock', 
    array('ShowRecentPosts' => _t('显示最新文章'),
    'ShowRecentComments' => _t('显示最近回复'),
    'ShowCategory' => _t('显示分类'),
    'ShowArchive' => _t('显示归档'),
    'ShowOther' => _t('显示其它杂项')),
    array('ShowRecentPosts', 'ShowRecentComments', 'ShowCategory', 'ShowArchive', 'ShowOther'), _t('侧边栏显示'));
    
    $form->addInput($sidebarBlock->multiMode());
}

function img_postthumb($cid) {
    $db = Typecho_Db::get();
    $rs = $db->fetchRow($db->select('table.contents.text')
       ->from('table.contents')
       ->where('table.contents.cid=?', $cid)
       ->order('table.contents.cid', Typecho_Db::SORT_ASC)
       ->limit(1));
    preg_match_all("/[a-zA-z]+:\/\/[^\s]*.(png|jpeg|jpg|gif|bmp)/", $rs['text'], $thumbUrl);  //通过正则式获取图片地址
    $img_src = $thumbUrl[0][0];
    $img_counter = count($thumbUrl[0]);
    switch ($img_counter > 0) {
        case $allPics = 1:
           echo $img_src;
           break;
        default:
           echo "";
    };
}

/*
function themeFields($layout) {
    $logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点LOGO地址'), _t('在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO'));
    $layout->addItem($logoUrl);
}
*/

